package xyz.xiangyushui.util.dataBase.client;

import java.util.Scanner;

import xyz.xiangyushui.util.dataBase.client.command.Command;
import xyz.xiangyushui.util.dataBase.client.command.seedCommand.SeedCommandExecutor;
import xyz.xiangyushui.util.dataBase.client.command.seedCommand.SeedCommandParser;

public class Main {
	private final String cmdPrompt="ivan@dessertHouse:";
	private SeedCommandParser parser;
	private SeedCommandExecutor executor;
	private Scanner scanner;
	
	public Main(){
		parser=new SeedCommandParser();
		executor=new SeedCommandExecutor();
		scanner=new Scanner(System.in);
	}
	
	public void run(){
		String cmd=nextCommand();
		while(!"exit".equals(cmd)){
			try{
				Command c=parser.compile(cmd);
				executor.execute(c);				
			}catch(IllegalArgumentException e){
				System.err.println(e.getMessage());
			}
			cmd=nextCommand();
		}
		scanner.close();
		System.out.println("bye bye!");
	}
	
	private String nextCommand(){
		System.out.print(cmdPrompt);
		return scanner.nextLine();
	}
	
	public static void main(String[] args){
		Main m=new Main();
		m.run();
	}
}
